﻿
using System.Collections.Generic;
using System.Net;
using System.Text;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Web.Routing;
using Microsoft.Practices.ServiceLocation;

namespace MvcMall.Framework.Helpers
{
    /// <summary>
    /// System.Web.Mvc.ViewMasterPage 扩展HTML工具类
    /// </summary>
    public static class HtmlHelperExtensions
    {
        /// <summary>
        /// 生成CSS的链接
        /// </summary>
        /// <param name="html"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static MvcHtmlString StyleSheet(this HtmlHelper html, string fileName)
        {
            var urlHelper = new UrlHelper(html.ViewContext.RequestContext);
            var tagBuilder = new TagBuilder("link");

            tagBuilder.MergeAttribute("href", urlHelper.StyleSheet(fileName));
            tagBuilder.MergeAttribute("rel", "stylesheet");
            tagBuilder.MergeAttribute("type", "text/css");

            return MvcHtmlString.Create(tagBuilder.ToString(TagRenderMode.Normal));
        }



        /// <summary>
        /// 生成Scrip的链接
        /// </summary>
        /// <param name="html"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static MvcHtmlString JavaScript(this HtmlHelper html, string fileName)
        {
            var urlHelper = new UrlHelper(html.ViewContext.RequestContext);
            var tagBuilder = new TagBuilder("script");

            tagBuilder.MergeAttribute("src", urlHelper.JavaScript(fileName));
            tagBuilder.MergeAttribute("type", "text/javascript");

            return MvcHtmlString.Create(tagBuilder.ToString(TagRenderMode.Normal));
        }



    }
}